﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using CPPProject.Configuration;
using CPPProject.Web;

namespace CPPProject.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class CPPProjectDbContextFactory : IDesignTimeDbContextFactory<CPPProjectDbContext>
    {
        public CPPProjectDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<CPPProjectDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            CPPProjectDbContextConfigurer.Configure(builder, configuration.GetConnectionString(CPPProjectConsts.ConnectionStringName));

            return new CPPProjectDbContext(builder.Options);
        }
    }
}
